/*!
 * \file frservice_get.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "conntrack.h"
#include "frct_comm.h"
#include "module.h"
#include "frreport_comm.h"
#include "frkyro.h"

#include "frct_expect.h"
#include "frservice_comm.h"

#include "apmtest_comm.h"

int frkyro_read_var_int(Frbyte_Packet *p_st_data
                      , int i_optimize_flg
                      , int *p_l_value);

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    int i_ret = FR_SUCC;
    int l_value = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\x01x04", 2);

    i_ret = frkyro_read_var_int(p_st_data, FR_NO, &l_value);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(l_value, 1);

    bytebuff_free(&p_st_data);
    return;
}

static void __case2(void)
{
    int i_ret = FR_SUCC;
    int l_value = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\xd8\x04", 2);

    i_ret = frkyro_read_var_int(p_st_data, FR_YES, &l_value);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_EQUAL(l_value, 300);

    bytebuff_free(&p_st_data);
    return;
}

static void __case3(void)
{
    int i_ret = FR_SUCC;
    int l_value = NULL;
    Frbyte_Packet *p_st_data = NULL;

    p_st_data = bytebuff_creat();
    bytebuff_add(p_st_data, (char *)"\xd8\x04", 1);

    i_ret = frkyro_read_var_int(p_st_data, FR_YES, &l_value);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    bytebuff_free(&p_st_data);
    return;
}

int add_suite_frkyro_read_var_int(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frkyro frkyro_read_var_int()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);

    return FR_SUCC;
}
